Laravel.form = {
    /**
     * @type String
     */
    "requiredClass": "inputError",
    /**
     * @param {object jQuery} input
     * @param {object jQuery} hidden
     * @param {object} data
     * @returns {undefined}
     */
    "setupAutocomplete": function (input, hidden, data)
    {
        input.autocomplete({
            "minLength": 0,
            "source": function (request, response) {
                var term = Core.accentStrip(request.term);
                var matcher = new RegExp($.ui.autocomplete.escapeRegex(term), "i");
                response($.grep(data, function (row) {
                    var label = row.label;
                    var test = matcher.test(label) || matcher.test(Core.normalize(label));
                    return test;
                }));
            },
            "focus": function (event, ui) {
                input.removeClass(Laravel.form.requiredClass);
                input.val(ui.item.label);
                hidden.val(ui.item.value);
                return false;
            },
            "select": function (event, ui) {
                input.removeClass(Laravel.form.requiredClass);
                input.val(ui.item.label);
                hidden.val(ui.item.value);
                return false;
            }
        }).blur(function () {
            var value = input.val();
            if (value === '') {
                hidden.val('');
            } else {
                var found = false;
                for (var i in data) {
                    if (value === data[i].label) {
                        found = true;
                    }
                }
                if (false === found) {
                    input.val('');
                    hidden.val('');
                    input.addClass(Laravel.form.requiredClass);
                }
            }
//        }).focus(function() {
        }).click(function () {
//            input.autocomplete('search', input.val());
            input.autocomplete('search', '');
        });
    },
    /**
     * @param {mixed} container
     * @returns {object jQuery}
     */
    "getInputsFromContainer": function (container) {
        container = (container) ? container : false;
        var inputs = $();

        if (!container) {
            inputs = $(':input');
        } else if (container.jquery) {
            if (container.is(':input')) {
                inputs = container;
            } else {
                inputs = container.find(':input');
            }
        } else {
            inputs = $(container + ' :input');
        }
        return inputs;
    },
    "configMultiFile": function (fileInput, multiple) {

        var file_id = fileInput.attr('id');
        var id = str_replace('FILE-', '', file_id);

        var table = $('#TB-' + id);
        var fileTitle = $('#TITULO-' + id);
        var ajax = new Laravel.Ajax();
        var lastRowIndex = 0;


        // Submetodo para travar o campo file caso o título não tenha sido digitado
        var lockFileInput = function () {
            if ($(fileTitle).val().length > 0) {
                $(fileInput).removeAttr('disabled');
                return;
            }
            $(fileInput).attr('disabled', 'disabled');
        }

        // Submetodo para upload do arquivo 
        var upload = function () {

            var data = new FormData();

            $.each($(fileInput)[0].files, function (i, file) {
                data.append(i, file);
            });

            data.append('TITULO', $(fileTitle).val());
            data.append('ROW_INDEX', lastRowIndex);

            $(fileInput).attr('disabled', 'disabled');
            $(fileTitle).val('');
            $(fileInput).val('');
            var container = $('#' + id);

            ajax.submit({
                "module": 'default',
                "controller": 'arquivo',
                "action": 'ajax-upload',
                "data": data,
                "contentType": false,
                "processData": false,
                "showLoading": false,
                "callback": function (result) {
                    Core.console.debug(result);

                    var row = $('#' + setRowID(result.ROW_INDEX));
                    var status = row.find('.status');
                    var extension = row.find('.extension');
                    status.find('img').remove();

                    if (result.RESULT == 1) {
                        var values = '{"COD": "0", "ACT": "I", "TITLE": "' + result[0].TITLE + '", "PATH": "' + result[0].PATH + '"}';
                        var field = "<option id='Inp_" + setRowID(result.ROW_INDEX) + "' value='" + values + "' SELECTED /> </option>";

                        status.append('OK');
                        extension.append('<img style="cursor:pointer;" src="' + baseUrl + "/public/images/Laravel/extentions/ico-" + result[0].EXTENSION + ".png" + '"> ' + result[0].EXTENSION);
                        container.append(field);

                    } else {

                        status.append('NOK');
                    }
                },
                "callbackError": function (result) {
                    $(fileInput).attr('disabled', 'disabled');
                    $(fileTitle).val('');
                    $(fileInput).val('');
                }
            });
        }

        var setBtnExcluir = function () {
            $('.multifileExcluir').unbind('click');
            $('.multifileExcluir').click(function () {
                var rowid = $(this).parents('tr').attr('id');
                var input = $('#Inp_' + rowid);
                var serialize = json_decode(input.val());
                if (serialize.ACT == 'I') {
                    input.remove();
                    $(this).parents('tr').remove();
                }

            });
        }

        // Submetodo que aplica id a nova linha da tabela
        var setRowID = function (index) {
            return id + '_ROW' + '_' + index;
        }

        var newline = function () {

            var index = $(table).find('tr').length;
            var row = '<tr id="' + setRowID(index) + '">' +
                    '<td>' +
                    fileTitle.val() +
                    '</td>' +
                    '<td class="extension">' + ' </td>' +
                    '<td class="status"> <img src="' + baseUrl + '/public/images/Laravel/bt/loading.gif' + '">' + ' </td>' +
                    '<td class="action">' +
                    '<input type="button" class="multifileExcluir" value="Excluir">' +
                    '</td>' +
                    '</tr>';

            if (multiple == false) {
                $(table).find('tr').remove();
            }

            $(table).append(row);

            setBtnExcluir();

            lastRowIndex = index;
        }

        // Trava o campo file ao carregar o formulário
        $(fileInput).attr('disabled', 'disabled');

        // Verifica se o campo file pode ser destravado ao receber foco
        $(fileInput).focus(function () {
            lockFileInput();
        });

        // Destrava o campo file ao digitar o texto do título
        $(fileTitle).keyup(function () {
            lockFileInput();
        });

        // Comportamento ao selecionar o arquivo
        $(fileInput).change(function () {
            lockFileInput();
            newline();
            upload();
        });
    },
    "configDocumentosDoPleito": function (fileInput, multiple) {

        var file_id = fileInput.attr('id');
        var id = str_replace('FILE-', '', file_id);

        var table = $('#TB-' + id);
        var fileTitle = $('#TITULO-' + id);
        var fileAdd = $('#ADD-' + id)
        var ajax = new Laravel.Ajax();
        var lastRowIndex = ((table.find('tr').length) - 1);


        // simula o evento de click no field de file      
        fileAdd.click(function () {
            fileInput.trigger('click')
        });

        // Submetodo para upload do arquivo 
        var upload = function () {

            var data = new FormData();

            $.each($(fileInput)[0].files, function (i, file) {
                data.append(i, file);
            });

            data.append('TITULO', 'Documento do Pleito');
            data.append('ROW_INDEX', lastRowIndex);

            $(fileInput).val('');
            var container = $('#' + id);

            ajax.submit({
                "module": 'basic',
                "controller": 'arquivo',
                "action": 'ajax-upload',
                "data": data,
                "contentType": false,
                "processData": false,
                "showLoading": false,
                "callback": function (result) {
                    Core.console.debug(result);

                    var row = $('#' + setRowID(result.ROW_INDEX));
                    var status = row.find('.status');
                    var extension = row.find('.extension');
                    var envio = row.find('.envio');
                    var usuario = row.find('.usuario');
                    status.find('img').remove();

                    var checar = row.find('.checar');


                    if (result.RESULT == 1) {
                        var values = '{"COD": "0", "CHECKED": "0", "ACT": "I", "TITLE": "' + result[0].TITLE + '", "PATH": "' + result[0].PATH + '"}';
                        var field = "<option id='Inp_" + setRowID(result.ROW_INDEX) + "' value='" + values + "' SELECTED /> </option>";

                        extension.append('<img style="cursor:pointer;" src="' + baseUrl + "/public/images/Laravel/extentions/ico-" + result[0].EXTENSION + ".png" + '"> ' + result[0].EXTENSION);
                        container.append(field);

                        checar.append('<input class="check" type="checkbox" id="CHECK-' + result.ROW_INDEX + '">');
                        setCheckbox();

                    } else {
                        status.append(result.ERROR_MESSAGE);
                    }

                    envio.append(result.DATE);
                    usuario.append(result.USER);
                },
                "callbackError": function (result) {
                    $(fileInput).attr('disabled', 'disabled');
                    $(fileTitle).val('');
                    $(fileInput).val('');
                }
            });
        }

        var setBtnExcluir = function () {

            var container = $('#' + id);

            $('.multifileExcluir').unbind('click');
            $('.multifileExcluir').click(function () {
                var rowid = $(this).parents('tr').attr('id');
                var input = $('#Inp_' + rowid);
                var serialize = json_decode(input.val());

                if (serialize == null) {
                    $(this).parents('tr').remove();
                } else if (serialize.ACT == 'I') {
                    input.remove();
                } else {
                    serialize.ACT = 'D';
                    input.val(json_encode(serialize));
                }
                $(this).parents('tr').remove();


            });
        }

        setBtnExcluir();

        var setCheckbox = function () {
            $('.check').unbind('click');
            $('.check').click(function () {

                var rowid = $(this).parents('tr').attr('id');
                var input = $('#Inp_' + rowid);
                var serialize = json_decode(input.val());

                Core.console.debug(serialize.CHECKED);

                if (serialize.CHECKED == 0) {
                    serialize.CHECKED = 1;
                } else if (serialize.CHECKED == 1) {
                    serialize.CHECKED = 0;
                }

                input.val(json_encode(serialize));

            });
        }

        setCheckbox();

        // Submetodo que aplica id a nova linha da tabela
        var setRowID = function (index) {
            return id + '_ROW' + '_' + index;
        }

        var newline = function () {

            var index = lastRowIndex + 1;
            var row = '<tr id="' + setRowID(index) + '">' +
                    '<td>' +
                    '<spam class="checar" style="float:left margin-bottom:3px;"></spam>' +
                    fileInput.val() + '<spam class="status extension" style="float:right"><img src="' + baseUrl + '/public/images/Laravel/bt/loading.gif' + '">' + ' </spam>' +
                    '</td>' +
                    '<td class="envio"></td>' +
                    '<td class="usuario"></td>' +
                    '<td class="action" align="center">' +
                    '<button type="button" class="multifileExcluir">X</button>' +
                    '</td>' +
                    '</tr>';

            if (multiple == false) {
                $(table).find('tr').remove();
            }

            $(table).append(row);

            setBtnExcluir();

            lastRowIndex = index;
        }

        // Comportamento ao selecionar o arquivo
        $(fileInput).change(function () {
            newline();
            upload();
        });
    },
    "configInstrucoesDeTrabalho": function (fileInput, multiple) {

        var file_id = fileInput.attr('id');
        var id = str_replace('FILE-', '', file_id);

        var table = $('#TB-' + id);
        var fileTitle = $('#TITULO-' + id);
        var fileAdd = $('#ADD-' + id)
        var ajax = new Laravel.Ajax();
        var lastRowIndex = ((table.find('tr').length) - 1);


        // simula o evento de click no field de file      
        fileAdd.click(function () {
            fileInput.trigger('click')
        });

        // Submetodo para upload do arquivo 
        var upload = function () {

            var data = new FormData();

            $.each($(fileInput)[0].files, function (i, file) {
                data.append(i, file);
            });

            data.append('TITULO', 'Documento do Pleito');
            data.append('ROW_INDEX', lastRowIndex);

            $(fileInput).val('');
            var container = $('#' + id);

            ajax.submit({
                "module": 'basic',
                "controller": 'arquivo',
                "action": 'ajax-upload',
                "data": data,
                "contentType": false,
                "processData": false,
                "showLoading": false,
                "callback": function (result) {
                    Core.console.debug(result);

                    var row = $('#' + setRowID(result.ROW_INDEX));
                    var status = row.find('.status');
                    var extension = row.find('.extension');
                    var envio = row.find('.envio');
                    var usuario = row.find('.usuario');
                    status.find('img').remove();




                    if (result.RESULT == 1) {
                        var values = '{"COD": "0", "ACT": "I", "TITLE": "' + result[0].TITLE + '", "PATH": "' + result[0].PATH + '"}';
                        var field = "<option id='Inp_" + setRowID(result.ROW_INDEX) + "' value='" + values + "' SELECTED /> </option>";

                        extension.append('<img style="cursor:pointer;" src="' + baseUrl + "/public/images/Laravel/extentions/ico-" + result[0].EXTENSION + ".png" + '"> ' + result[0].EXTENSION);
                        container.append(field);

                        setCheckbox();

                    } else {
                        status.append(result.ERROR_MESSAGE);
                    }

                    envio.append(result.DATE);
                    usuario.append(result.USER);
                },
                "callbackError": function (result) {
                    $(fileInput).attr('disabled', 'disabled');
                    $(fileTitle).val('');
                    $(fileInput).val('');
                }
            });
        }

        var setBtnExcluir = function () {

            var container = $('#' + id);

            $('.multifileExcluir').unbind('click');
            $('.multifileExcluir').click(function () {
                var rowid = $(this).parents('tr').attr('id');
                var input = $('#Inp_' + rowid);
                var serialize = json_decode(input.val());

                if (serialize == null) {
                    $(this).parents('tr').remove();
                } else if (serialize.ACT == 'I') {
                    input.remove();
                } else {
                    serialize.ACT = 'D';
                    input.val(json_encode(serialize));
                }
                $(this).parents('tr').remove();


            });
        }

        setBtnExcluir();

        // Submetodo que aplica id a nova linha da tabela
        var setRowID = function (index) {
            return id + '_ROW' + '_' + index;
        }

        var newline = function () {

            var index = lastRowIndex + 1;
            var row = '<tr id="' + setRowID(index) + '">' +
                    '<td>' +
                    fileInput.val() + '<spam class="status extension" style="float:right"><img src="' + baseUrl + '/public/images/Laravel/bt/loading.gif' + '">' + ' </spam>' +
                    '</td>' +
                    '<td class="action" align="center">' +
                    '<button type="button" class="multifileExcluir">X</button>' +
                    '</td>' +
                    '</tr>';

            if (multiple == false) {
                $(table).find('tr').remove();
            }

            $(table).append(row);

            setBtnExcluir();

            lastRowIndex = index;
        }

        // Comportamento ao selecionar o arquivo
        $(fileInput).change(function () {
            newline();
            upload();
        });
    },
    /**
     * @param {mixed} container
     * @returns {undefined}
     */
    "setupInputs": function (container) {
        Core.console.group('Setup inputs...', true);
        Laravel.boxSelect.activate();
        try {
            container = container || $("body");
            if (typeof (container) === "string") {
                container = $(container);
            }
            if (!isset(container.jquery)) {
                throw new Core.Exception("Core.form.setupInputs: passe um seletor válido ou um objeto jQuery.");
            }
            Core.console.debug(container, 'container');
           
            var inputs = this.getInputsFromContainer(container);
            inputs.each(function () {
                var input = $(this);
                
                var configDefaultDatepicker = {
                    "dateFormat": "dd/mm/yy",
                    "showOn": "button",
                    "buttonImage": "/public/images/Laravel/ico/ico_calendario.png",
                    "buttonImageOnly": true,
                    "changeMonth": true,
                    "changeYear": true,
                    "yearRange": "-20:+20",
                    "buttonText": "Escolher Data...",
                    "dayNamesMin": ["Dom", "Seg", "Ter", "Qui", "Qua", "Sex", "Sab"],
                    "monthNamesShort": ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"],
                    "monthNames": ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"]
                };



                var controlType = input.attr('data-ng-controltype');
                if (isset(controlType)) {
                    var controlTypeSplited = controlType.split('-');
                    var controlTypeName = controlTypeSplited[0];
                    var controlTypeComplement = controlTypeSplited[1];

                    Core.console.debug(sprintf("controlType: %s", controlType), input.attr('id'), Core.console.type.INFO);
                   
                    switch (controlTypeName) {

                        //Laravel controltypes


                        //Core controltypes
                        case 'uf':
                            input.bind('change', function () {
                                //se tiver um dependente não está em um subform
                                var dependent = $(input.attr('dependent'));
                                if (dependent.length == 0) {
                                    var msg = "Para integração de uf com cidade é obrigatório adicionar ";
                                    msg += "um elemento dependente (combo cidade) ao input: ";
                                    msg += input.attr('id');
                                    msg += " Veja exemplo em 'default/exemplo/formulario'";
                                    Core.console.debug(msg);
                                }
                                //se ainda não existir um dependente é por que não foi setado, não faz nada
                                if (dependent.length) {
                                    input.getMunicipioByUf();

                                    if (input.hasClass('required')) {
                                        dependent.addClass('required');
                                    }

                                    if (input.val() == '' && !input.hasClass('required')) {
                                        dependent.removeClass('required');
                                    }
                                }
                            });
                            break;
                        case 'cpf':
                            input.mask('999.999.999-99');
                                    //.data('validateFunction', Core.validate.cpf);
                                    //.css('text-align', 'center');
                            break;
                        case 'cnpj':
                            input.mask('99.999.999/9999-99')
                                    .data('validateFunction', Core.validate.cnpj)
                                    .css('text-align', 'center');
                            break;
                        case 'cep':
                            input.mask('99999-999')
                                    .css('text-align', 'center');
                            break;
                        case 'hour':
                            //@todo: implementar validador
                            input.data('validateFunction', Core.validate.hour)
                                    .mask("99:99")
                                    .css('text-align', 'center');
                            break;
                        case 'phone':
                            input.mask('(99) 9999-9999');
                            break;
                        case 'float': //has controlTypeComplement (integer with precision)
                            Core.console.debug('has controlTypeComplement (integer with precision)', input.attr('id'), Core.console.type.WARN);
                            //@todo: implementar validador
                            if (input.attr('maxlength')) {
                                input.data('validateFunction', isMaxlengthValid);
                            }
                            input.maskMoney({"precision": parseInt(controlTypeComplement)})
                                    .css('text-align', 'right');
                            break;
                        case 'float_zero_allowed': //has controlTypeComplement (integer with precision)
                            Core.console.debug('has controlTypeComplement (integer with precision)', input.attr('id'), Core.console.type.WARN);
                            input.maskMoney({"precision": parseInt(controlTypeComplement)})
                                    .css('text-align', 'right');
                            break;
                        case 'money':
                            input.maskMoney()
                                    .css('text-align', 'right');
                            break;
                        case 'integer':
                            input.data('validateFunction', Core.validate.integer)
                                    .bind({
                                        "keypress": function (event) {
                                            return Core.form.checkIntegerFromEvent(event);
                                        }
                                    });
                            break;
                        case 'integer_with_zero':
                            input.data('validateFunction', Core.validate.integer)
                                    .bind({
                                        "keypress": function (event) {
                                            return Core.form.checkIntegerFromEvent(event);
                                        },
                                        "focus": function () {
                                            if (parseInt($(this).val(), 10) === 0) {
                                                $(this).val('');
                                            }
                                        },
                                        "change blur": function () {
                                            Core.form.forceZeroInBlankValue(input);
                                        }
                                    });
                            Core.form.forceZeroInBlankValue(input);
                            break;
                        case 'day':
                            input.data('validateFunction', Core.validate.date)
                                    .attr('maxlength', '2')
                                    .bind({
                                        "keypress": function (event) {
                                            return Core.form.checkIntegerFromEvent(event);
                                        }
                                    });
                            break;
                        case 'year':
                            input.mask('9999')
                                    .css('text-align', 'center');
                            break;
                        case 'month_year':
                            input.data('validateFunction', Core.validate.date)
                                    .mask('99/9999')
                                    .css('text-align', 'center');
                            break;
                        case 'date':
                            input.data('validateFunction', Core.validate.date)
                                    .mask('99/99/9999')
                                    .css('text-align', 'center')
                                    .datepicker(configDefaultDatepicker);
                            break;
                        case 'init_date':
                            input.data('validateFunction', Core.validate.isInitDateValid)
                                    .mask('99/99/9999')
                                    .css('text-align', 'center')
                                    .datepicker(configDefaultDatepicker);
                            break;
                        case 'final_date':
                            input.data('validateFunction', Core.validate.isFinalDateValid)
                                    .mask('99/99/9999')
                                    .css('text-align', 'center')
                                    .datepicker(configDefaultDatepicker);
                            break;
                        case 'date_before_today':
                            //@todo: implementar validador
                            input.data('validateFunction', isDateBeforeToday)
                                    .mask('99/99/9999')
                                    .css('text-align', 'center')
                                    .datepicker($.extend({"maxDate": "-1d"}, configDefaultDatepicker));
                            break;
                        case 'date_before_tomorrow':
                            //@todo: implementar validador
                            input.data('validateFunction', isDateBeforeTomorrow)
                                    .mask('99/99/9999')
                                    .css('text-align', 'center')
                                    .datepicker($.extend({"maxDate": "d"}, configDefaultDatepicker));
                            break;
                        case 'date_after_today':
                            //@todo: implementar validador
                            input.data('validateFunction', isDateAfterToday)
                                    .mask('99/99/9999')
                                    .css('text-align', 'center')
                                    .datepicker($.extend({"minDate": "+1d"}, configDefaultDatepicker));
                            break;
                        case 'date_after_yesterday':
                            //@todo: implementar validador
                            input.data('validateFunction', isDateAfterYesterday)
                                    .mask('99/99/9999')
                                    .css('text-align', 'center')
                                    .datepicker($.extend({"minDate": "d"}, configDefaultDatepicker));
                            break;
                        case 'email':
                            input.data('validateFunction', Core.validate.email)
                                    .css('text-transform', 'lowercase');
                            break;
                        case 'separated_words': //has controlTypeComplement (upper_case|lower_case)
                            Core.console.debug('has controlTypeComplement (upper_case|lower_case)', input.attr('id'), Core.console.type.WARN);
                            //@todo: implementar validador
                            input.data('validateFunction', isValorCompostoValid);
                            if (controlTypeComplement === 'upper_case') {
                                input.css({
                                    "text-transform": "uppercase"
                                })
                                        .blur(function () {
                                            input.val(input.val().toUpperCase());
                                        });
                            } else if (controlTypeComplement === 'lower_case') {
                                input.css({
                                    "text-transform": "lowercase"
                                })
                                        .blur(function () {
                                            input.val(input.val().toLowerCase());
                                        });
                            }
                            break;
                        case 'no_separated_words': //has controlTypeComplement (upper_case|lower_case)
                            Core.console.debug('has controlTypeComplement (upper_case|lower_case)', input.attr('id'), Core.console.type.WARN);
                            //@todo: implementar validador
                            input.data('validateFunction', isValorSimplesValid);

                            if (controlTypeComplement === 'upper_case') {
                                input.css({"text-transform": "uppercase"})
                                        .blur(function () {
                                            input.val(input.val().toUpperCase());
                                        });
                            } else if (controlTypeComplement === 'lower_case') {
                                input.css({"text-transform": "lowercase"})
                                        .blur(function () {
                                            input.val(input.val().toLowerCase());
                                        });
                            }
                            break;
                        case 'upper_case':
                            input.css({"text-transform": "uppercase"})
                                    .blur(function () {
                                        input.val(input.val().toUpperCase());
                                    });
                            break;
                        case 'lower_case':
                            input.css({"text-transform": "lowercase"})
                                    .blur(function () {
                                        input.val(input.val().toLowerCase());
                                    });
                            break;

                        case 'editor' :
                            tinymce.init({selector: '#' + input.attr('id')});
                            input.addClass('hasEditor');
                            var div = input.parent('div');
                            if (input.hasClass('required')) {
                                div.addClass('required');
                            }
                            Core.console.debug('div = ' + div.attr('class'));

                            break;
                        case 'core_multifile' :

                            //input.change(function() {
                            Laravel.form.configMultiFile(input, true);
                            // });

                            break;
                        case 'core_documentos_do_pleito' :

                            //input.change(function() {
                            Laravel.form.configDocumentosDoPleito(input, true);
                            // });

                            break;

                        case 'core_instrucoes_de_trabalho' :

                            //input.change(function() {
                            Laravel.form.configInstrucoesDeTrabalho(input, true);
                            // });

                            break;

                        case 'core_simplefile' :
                            //input.change(function() {
                            Laravel.form.configMultiFile(input, false);
                            // });

                            break;

                        case 'captcha' :
                            input.addClass('required');
                            break;

                        case 'protocol' :
                            input.mask('99999.999999/9999-99').css('text-align', 'center');
                            break;



                        default:
                            Core.console.debug('Control Type não definido!', input.attr('id'), Core.console.type.ERROR);
                            break;
                    }
                }

//                if (input.is('[type=reset]')) {
//                    Core.console.debug('input.is("[type=reset]")', input.attr('id'), Core.console.type.INFO);
//                    input.bind("click", function() {
//                        input.parents("form").reset();
//                    });
//                }

                if (input.is('input[type=hidden]')) {
                    Core.console.debug("input.is('input[type=hidden]')", input.attr('id'), Core.console.type.INFO);
                    input.data("defaultValue", input.val());
                }

                if (input.is(':checkbox')) {
                    /*Core.console.debug("input.is(':checkbox')", input.attr('id'), Core.console.type.INFO);
                     
                     var disabledCheckbox = input.attr('disabled');
                     var titleCheckbox = input.attr('title');
                     
                     input.button();
                     
                     if (disabledCheckbox) {
                     input.button('disable');
                     }
                     
                     input.prev('label').attr('title', titleCheckbox); */
                }

                if (input.is(':radio')) {
                    //@todo comentei provisoriamente para os radios do NPNE funcionarem
                    /*Core.console.debug("input.is(':radio')", input.attr('id'), Core.console.type.INFO);
                     
                     var disabledRadio = input.attr('disabled');
                     var titleRadio = input.attr('title');
                     
                     var radioContainer = input.parent();
                     radioContainer.buttonset().find("label:last").addClass("ui-corner-right");
                     
                     if (disabledRadio) {
                     input.button('disable');
                     }
                     
                     input.prev('label').attr('title', titleRadio);*/
                }


                if (input.is('textarea')) {
                    Core.console.debug("input.is('textarea') && input.attr('maxlength')", input.attr('id'), Core.console.type.INFO);
                    clearInterval(input.data('charCounterInterval'));

                    input.data('charCounterInterval', setInterval(function () {
                        Core.form.charCounter(input);
                    }, 1000));

                    input.bind({
                        "keyup": function () {
                            Core.form.textareaLimited(input);
                        },
                        "change": function () {
                            Core.form.textareaLimited(input);
                        },
                        "blur": function () {
                            Core.form.textareaLimited(input);
                        },
                        "focusout": function () {
                            Core.form.textareaLimited(input);
                        },
                        "focus": function () {
                            Core.form.textareaLimited(input);
                        }
                    });
                }

                if (input.is('select')) {
                    if (input.attr("readonly")) {
                        Core.console.debug("input.is('select') && input.attr('readonly')", input.attr('id'), Core.console.type.INFO);
                        input.attr("readonly", "readonly");
                    }
                    if (input.find('.inactiveOption').length > 0) {
                        Core.console.debug("input.is('select') && input.find('.inactiveOption')", input.attr('id'), Core.console.type.INFO);
//                        input.one( "focus", function() {
                        input.bind("focus", function () {
                            $(this).find(".inactiveOption").attr("disabled", "disabled");
                        });
                    }
                }

                var minlength = parseInt(input.attr('minlength'));
                if (minlength > 0) {
                    if (!isNaN(minlength)) {
                        Core.console.debug("input.attr('minlength')", input.attr('id'), Core.console.type.INFO);
                        input.data("validateFunction", hasMinimalValue);
                    }
                }
//@todo: isso não exite nesse sistema...
//                input.blur(input.baseValidate);
            });

        } catch (e) {
            Core.exceptionHandler(e);
        }
        Core.console.groupEnd();
    }
};